package com.lc1993929.mr.flowlog.enhance;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;

/**
 * Created by LiuChang on 2018/1/8.
 */
public class DBLoader {

    public static void load(HashMap<String, String> ruleMap) {
        Connection connection = null;
        Statement statemen = null;
        ResultSet resultSet = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            DriverManager.getConnection("jdbc:mysql://hdp1:3306/ruledb", "root", "root");
            statemen = connection.createStatement();
            resultSet = statemen.executeQuery("SELECT url ,content FROM t_rule");
            while (resultSet.next()) {
                String url = resultSet.getString(1);
                String content = resultSet.getString(2);
                ruleMap.put(url, content);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (resultSet != null) {
                    resultSet.close();
                }
                if (statemen != null) {
                    statemen.close();
                }
                if (connection != null) {
                    connection.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
